import axios from 'axios'
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'

//拦截请求头
axios.interceptors.request.use((config)=>{
    Nprogress.start()
    const token=window.localStorage.getItem('token');
    if(token){
        config.headers.authrization='Bearer '+token
    }
    return config
})


//拦截响应
axios.interceptors.response.use(response=>{
    Nprogress.done()
    return response.data
},err=>{
    // if(err.response.status){
    //     const {status}=err.response
    //     switch(status){
    //         case 404:
    //         return window.location.href='/404'
    //         case 401:
    //         return window.location.href='/login'
    //         case 500:
    //         return window.location.href='/500'
    //         default :break
    //     }
    // }
    return Promise.reject(err)
})

export default axios